package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Dao.ListDao;
import entity.Event;

/**
 * Servlet implementation class addEvent
 */
@WebServlet("/addEvent")
public class addEvent extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addEvent() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
		
		ListDao dao = new ListDao();
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");

		String title = request.getParameter("title");
		String start = request.getParameter("start");
		String end = request.getParameter("end");
		String className = request.getParameter("className");
		int id = dao.findNum()+1;
		System.out.println("id:"+id);
		
		Event event = new Event();
		event.setId(id);
		event.setTitle(title);
		event.setClassName(className);
		event.setStart(start);
		event.setEnd(end);

		dao.addEvent(event);		
	}

}
